<template>
	<view v-if="type==0">
		<view class="canvas">
			<canvas canvas-id="barcode"></canvas>
		</view>
		<text class="number">{{Messges.CpnNumber}}</text>
		<view class="divider"></view>
		<view class="box">
			<text class="title">{{Messges.CpnName}}</text>
			<view class="explain">
				<text>使用规则:</text>
				<text>满{{Messges.FMinValue}}元,立减{{Messges.FValue}}元</text>
			</view>
			<view class="explain">
				<text>使用门店:</text>
				<text>{{Messges.CorpName}}</text>
			</view>
			<view class="explain">
				<text>有效时间:</text>
				<text>{{Messges.StartTime}}-{{Messges.EndTime}}</text>
			</view>
		</view>
	</view>
	<view v-else>
		<view class="canvas">
			<canvas canvas-id="barcodeCard"></canvas>
		</view>
		<text class="number"></text>
		<view class="divider"></view>
		<view class="box">
			<!-- <view class="card-number">
				<text style="float: left;">开卡总量:<text class="ci_number">1次</text></text>
				<text style="float: right;">卡内剩余:<text class="ci_number">1次</text></text>
			</view> -->
			<text class="title">{{Messges.FName}}</text>
			<view class="explain">
				<text>次卡编码:</text>
				<text>{{Messges.FNumber}}</text>
			</view>
			<view class="explain">
				<text>剩余次数:</text>
				<text>{{Messges.FQty}}</text>
			</view>
			<view class="explain">
				<text>有效期到:</text>
				<text>{{Messges.FStatusDesc}}</text>
			</view>
			<view class="explain">
				<text>适用门店:</text>
				<text>{{Messges.FStockName}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				type: '',
				Messges: {},
			};
		},
		onLoad(options) {
			this.id = options.id;
			this.type = options.type;
			if(options.type==0){
				this.loaded('membershop/CouponDtl',{sendId:this.id});
			}else{
				this.loaded('membershop/MemberTimeDtl',{id:this.id});
			}
		},
		methods:{
			loaded(url,data){
				this.$util.util(url,data,'POST').then(res=>{
					this.Messges = res
					let member = uni.getStorageSync('Members');
					let storesID = uni.getStorageSync('stockId')
					let number = (res.FEntryID).toString() + '-' + member[0].MemberId + '-' + storesID;
					number = res.CpnNumber||number;
					let id = this.type==0?'barcode':'barcodeCard';
					this.$canvas.barcode(id, number, 480, 380);
				}).catch(error=>console.log(error));
			}
		}
	}
</script>

<style lang="scss">
	canvas{
		height: 100upx;
		width: 500upx;
	}
	.canvas{
		padding: 30upx;
		height: 150upx;
		width: 500upx;
		margin: auto;
	}
	.number{
		width: 100%;
		height: 50upx;
		line-height: 50upx;
		display: inline-block;
		text-align: center;
		font-weight: bold;
		font-size: 32upx;
		color: #000;
	}
	.divider{
		width: 100%;
		border: 4rpx dashed #F1F1F1;
		margin: 20upx 0;
	}
	.box{
		padding: 0 30upx;
		height: auto;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		.title{
			font-size: 38upx;
			font-weight: bold;
			color: #000;
			text-align: center;
		}
		.explain{
			width: 100%;
			line-height: 40rpx;
			margin: 20upx 0;
			text:first-child{
				color: #A2A2A2;
				margin-right: 20upx;
				float: left;
			}
			text:last-child{
				color: #000;
				display: inline-block;
				width: 530rpx;
				float: left;
			}
		}
		.card-number{
			width: 100%;
			line-height: 40upx;
			margin: 20upx 0;
			color: #A2A2A2;
			.ci_number{
				color: #4CD964;
				margin-left: 20upx;
			}
		}
	}
	
</style>
